package cn.itsource.service.impl;

import cn.itsource.config.anno.MyLog;
import cn.itsource.domain.BlogFriendAddress;
import cn.itsource.domain.SysOperLog;
import cn.itsource.mapper.SysOperLogMapper;
import cn.itsource.query.SysOperLogQuery;
import cn.itsource.service.BlogSysOperLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 实现业务层的接口
 */
@Service
public class BlogSysOperLogServiceimpl implements BlogSysOperLogService {

//    注入mapper层
    @Autowired
    private SysOperLogMapper mapper;


    @Override
    public SysOperLog findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysOperLog> findAll() {
        //使用tk的方法查询全部
        return mapper.selectAll();
    }

    @Override
    public void delete(Long id) {
        //        使用tk的方法删除
        mapper.deleteByPrimaryKey(id);

    }
    @Override
    public void save(SysOperLog sysOperLog) {
        //        使用tk的方法
        mapper.insertSelective(sysOperLog);

    }
    @Override
    public PageInfo<SysOperLog> pageList(SysOperLogQuery query) {
        PageHelper.startPage(query.getPage(),query.getRows());
        //高级查询，封装查询条件 参数：查询的domain的class类型
        Example example = new Example(BlogFriendAddress.class);
        //判断keyword是有效值
        if (StringUtils.isNotBlank(query.getKeyword())){
            example.and().andLike("realName","%"+query.getKeyword()+"%");
            example.or().orLike("content","%"+query.getKeyword()+"%");
        }
        List<SysOperLog> blogFriendAddresses = mapper.selectByExample(example);
        //封装成pageInfo
        PageInfo<SysOperLog> pageInfo = new PageInfo<>(blogFriendAddresses);
        //返回数据
        return pageInfo;
    }


}
